﻿using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Crystal.CustomControls
{
    public static class CommonCustomControls
    {
        //public static System.Drawing.Color GetFormBackColor()
        //{

        //    int[] Values = new int[3];
        //    if (IsValidString(ConfigurationManager.AppSettings("FormBackColor"), Values))
        //    {
        //        return System.Drawing.Color.FromArgb(Values[0], Values[1], Values[2]);
        //    }
        //}

        /// <summary>
        /// Checks the Valid String (RGB color)
        /// </summary>
        /// <param name="StrColor"></param>
        /// <param name="lintValues"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static bool IsValidString(string StrColor, ref int[] lintValues)
        {
            string[] str = null;
            try
            {
                if (!string.IsNullOrEmpty(StrColor))
                {

                    str = StrColor.Split(',');
                    if (str.Length == 3)
                    {
                        for (Int16 i = 0; i <= str.Length - 1; i++)
                        {

                            if (IsNumeric(str[i]))
                            {
                                lintValues[i] = Convert.ToInt32(str[i]);
                                if (lintValues[i] > 255)
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                return false;
                            }
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Crystal", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //'Logging
            }
            return true;
        }

        private static bool IsNumeric(string ValueToCheck)
        {
            double Dummy = new double();
            string InputValue = Convert.ToString(ValueToCheck);

            bool Numeric = double.TryParse(InputValue, System.Globalization.NumberStyles.Any, null, out Dummy);

            return Numeric;
        }

    }
}
